
#include "aux.hpp"

#include "common.hpp"

#include <cstring>

// Proc

void Proc::send(const char *str) const
{
	lseek(fd, 0, 0);
	std::cout << "write: " << str << std::endl;
	if(write(fd, str, strlen(str)) < 0)
		throw ProcOperationFailed();
}

std::string Proc::receive() const
{
	char buf[read_buf_max];
		
	memset(buf, '\0', read_buf_max);

	lseek(fd, 0, 0);
	
	if(read(fd, buf, read_buf_max) < 0) {
		throw ProcOperationFailed();

	}

	return std::string(buf);
}
